---
title: "ANES Attitude Stablity"
output: html_document
---
#Load Data Sets
```{r}
library(tidyverse)
library(survey)
library(scales)
library(ggpubr)
library(rio)
load("compiled_data.Rdata")

table(anes_combined$Year)

table(anes_combined$white)

anes_combined=subset(anes_combined,white==1)
```

Rescale Family Ties Variable (used as a comparison in the appendix as it is the only variable that is identically worded across surveys)
```{r}
anes_combined$morefamilyties_rescaled=rescale(anes_combined$morefamilyties)

```


Reorder religion varable (1=Protestant, 2=Evangelical, 3=Catholic, 4=Other Denomination/Religion), note that there is no evangelical code in the 2004 ANES
```{r}
table(anes_combined$religion)
anes_combined$religion=factor(anes_combined$religion, levels =c(1,2,3,4) )
table(anes_combined$religion[anes_combined$Year==2004])
```

Plotting Gender/Feminist Attitudes and Racial Resentment Across Years
```{r}
yearly_averages= anes_combined  %>%group_by(Year) %>%
  summarize(racial_resentment_average= weighted.mean(racial_resentment, w=weight_variable, na.rm=T),traditional_values_index_average= weighted.mean(traditional_values_index, w=weight_variable, na.rm=T),modern_sexism_index_average= weighted.mean(modern_sexism_index, w=weight_variable, na.rm=T),percieved_gender_discrimination_average= weighted.mean(percieved_gender_discrimination_rescaled, w=weight_variable, na.rm=T),ft_feminists_average= weighted.mean(ft_feminists, w=weight_variable, na.rm=T),morefamilyties_average= weighted.mean(morefamilyties_rescaled, w=weight_variable, na.rm=T))


racialresentment_plot=ggplot(data =yearly_averages, aes(x=Year, y=racial_resentment_average))+geom_line()+
  geom_point() +ylim(0,1)+ylab("Average Racial Resentment")+ xlab("Year")+ggtitle("Racial Resenment")

traditionalvalues_plot=ggplot(data =yearly_averages, aes(x=Year, y=traditional_values_index_average))+geom_line()+
  geom_point() +ylim(0,1)+ylab("Average Traditional Family Values")+ xlab("Year")+ggtitle("Traditional Family Values")
  
modernsexism_plot= ggplot(data =yearly_averages, aes(x=Year, y=modern_sexism_index_average))+geom_line()+
  geom_point() +ylim(0,1)+ylab("Average Modern Sexism")+ xlab("Year") + ggtitle("Modern Sexism")

genderdiscrimination_plot= ggplot(data =yearly_averages, aes(x=Year, y=percieved_gender_discrimination_average))+geom_line()+
  geom_point() +ylim(0,1)+ylab("Average Gender Discrimination")+ xlab("Year") + ggtitle("Gender Discrimination")

ft_feminist_plot= ggplot(data =yearly_averages, aes(x=Year, y=ft_feminists_average))+geom_line()+
  geom_point() +ylim(0,1)+ylab("Average Feminist Feeling Thermometer")+ xlab("Year") + ggtitle("Feminist Feeling Thermometer")

more_familyties_plot= ggplot(data =yearly_averages, aes(x=Year, y=morefamilyties_average))+geom_line()+
  geom_point() +ylim(0,1)+ylab("Average Family Ties")+ xlab("Year") + ggtitle("Family Ties")


together = ggarrange(racialresentment_plot,traditionalvalues_plot,modernsexism_plot,genderdiscrimination_plot,ncol = 2,nrow  = 2,font.label = list(size=12),vjust = .5)

ggexport(together,filename = "Tables and Figures/Average Scores By Year_RR.pdf",height =6,width = 7 )

together = ggarrange(racialresentment_plot,traditionalvalues_plot,modernsexism_plot,genderdiscrimination_plot,ft_feminist_plot,more_familyties_plot,ncol = 2,nrow  = 3,font.label = list(size=12),vjust = .5)

ggexport(together,filename = "Tables and Figures/Average Scores By Year_RR_appendix.pdf",height =9,width = 7 )

library(xtable)

ya=data.frame(t(yearly_averages))
colnames(ya)=c("2004","2008","2012","2016","2020")
ya=ya[-1,]
rownames(ya)=c("Racial Resentment","Traditional Family Roles","Modern Sexism","Percieved Discrimination","Feminist Feeling Thermometer", "Family Ties")

print(xtable(ya),type="html",file="Tables and Figures/Descriptive Stats of Primary Variables.doc")
```


Plotting Bivariate Correlations by year
```{r}
library(weights)
#Traditional Family Values
trad_val=data.frame(rbind(wtd.cor(anes_combined$racial_resentment[anes_combined$Year==2004],anes_combined$traditional_values_index[anes_combined$Year==2004], weight =anes_combined$weight_variable[anes_combined$Year==2004]),wtd.cor(anes_combined$racial_resentment[anes_combined$Year==2008],anes_combined$traditional_values_index[anes_combined$Year==2008], weight =anes_combined$weight_variable[anes_combined$Year==2008]),wtd.cor(anes_combined$racial_resentment[anes_combined$Year==2012],anes_combined$traditional_values_index[anes_combined$Year==2012], weight =anes_combined$weight_variable[anes_combined$Year==2012]), wtd.cor(anes_combined$racial_resentment[anes_combined$Year==2016],anes_combined$traditional_values_index[anes_combined$Year==2016], weight =anes_combined$weight_variable[anes_combined$Year==2016]),wtd.cor(anes_combined$racial_resentment[anes_combined$Year==2020],anes_combined$traditional_values_index[anes_combined$Year==2020], weight =anes_combined$weight_variable[anes_combined$Year==2020])))

trad_val$CI=1.96*trad_val$std.err
trad_val$Year=c("2004","2008","2012","2016","2020")

#Modern Sexism
mod_sex=data.frame(rbind(wtd.cor(anes_combined$racial_resentment[anes_combined$Year==2004],anes_combined$modern_sexism_index[anes_combined$Year==2004], weight =anes_combined$weight_variable[anes_combined$Year==2004]),wtd.cor(anes_combined$racial_resentment[anes_combined$Year==2008],anes_combined$modern_sexism_index[anes_combined$Year==2008], weight =anes_combined$weight_variable[anes_combined$Year==2008]),wtd.cor(anes_combined$racial_resentment[anes_combined$Year==2012],anes_combined$modern_sexism_index[anes_combined$Year==2012], weight =anes_combined$weight_variable[anes_combined$Year==2012]), wtd.cor(anes_combined$racial_resentment[anes_combined$Year==2016],anes_combined$modern_sexism_index[anes_combined$Year==2016], weight =anes_combined$weight_variable[anes_combined$Year==2016]),wtd.cor(anes_combined$racial_resentment[anes_combined$Year==2020],anes_combined$modern_sexism_index[anes_combined$Year==2020], weight =anes_combined$weight_variable[anes_combined$Year==2020])))

mod_sex$CI=1.96*mod_sex$std.err
mod_sex$Year=c("2004","2008","2012","2016","2020")

#Perceived Gender Discrimination
gen_dis=data.frame(rbind(wtd.cor(anes_combined$racial_resentment[anes_combined$Year==2004],anes_combined$percieved_gender_discrimination_rescaled[anes_combined$Year==2004], weight =anes_combined$weight_variable[anes_combined$Year==2004]),wtd.cor(anes_combined$racial_resentment[anes_combined$Year==2008],anes_combined$percieved_gender_discrimination_rescaled[anes_combined$Year==2008], weight =anes_combined$weight_variable[anes_combined$Year==2008]),wtd.cor(anes_combined$racial_resentment[anes_combined$Year==2012],anes_combined$percieved_gender_discrimination_rescaled[anes_combined$Year==2012], weight =anes_combined$weight_variable[anes_combined$Year==2012]), wtd.cor(anes_combined$racial_resentment[anes_combined$Year==2016],anes_combined$percieved_gender_discrimination_rescaled[anes_combined$Year==2016], weight =anes_combined$weight_variable[anes_combined$Year==2016]),wtd.cor(anes_combined$racial_resentment[anes_combined$Year==2020],anes_combined$percieved_gender_discrimination_rescaled[anes_combined$Year==2020], weight =anes_combined$weight_variable[anes_combined$Year==2020])))
gen_dis$CI=1.96*gen_dis$std.err
gen_dis$Year=c("2004","2008","2012","2016","2020")


#Feminist Feeling Thermometer
ft_fem=data.frame(rbind(wtd.cor(anes_combined$racial_resentment[anes_combined$Year==2004],anes_combined$ft_feminists[anes_combined$Year==2004], weight =anes_combined$weight_variable[anes_combined$Year==2004]),wtd.cor(anes_combined$racial_resentment[anes_combined$Year==2008],anes_combined$ft_feminists[anes_combined$Year==2008], weight =anes_combined$weight_variable[anes_combined$Year==2008]),wtd.cor(anes_combined$racial_resentment[anes_combined$Year==2012],anes_combined$ft_feminists[anes_combined$Year==2012], weight =anes_combined$weight_variable[anes_combined$Year==2012]), wtd.cor(anes_combined$racial_resentment[anes_combined$Year==2016],anes_combined$ft_feminists[anes_combined$Year==2016], weight =anes_combined$weight_variable[anes_combined$Year==2016]),wtd.cor(anes_combined$racial_resentment[anes_combined$Year==2020],anes_combined$ft_feminists[anes_combined$Year==2020], weight =anes_combined$weight_variable[anes_combined$Year==2020])))

ft_fem$CI=1.96*ft_fem$std.err
ft_fem$Year=c("2004","2008","2012","2016","2020")


#More Family Ties
fam_ties=data.frame(rbind(wtd.cor(anes_combined$racial_resentment[anes_combined$Year==2004],anes_combined$morefamilyties_rescaled[anes_combined$Year==2004], weight =anes_combined$weight_variable[anes_combined$Year==2004]),wtd.cor(anes_combined$racial_resentment[anes_combined$Year==2008],anes_combined$morefamilyties_rescaled[anes_combined$Year==2008], weight =anes_combined$weight_variable[anes_combined$Year==2008]),wtd.cor(anes_combined$racial_resentment[anes_combined$Year==2012],anes_combined$morefamilyties_rescaled[anes_combined$Year==2012], weight =anes_combined$weight_variable[anes_combined$Year==2012]), wtd.cor(anes_combined$racial_resentment[anes_combined$Year==2016],anes_combined$morefamilyties_rescaled[anes_combined$Year==2016], weight =anes_combined$weight_variable[anes_combined$Year==2016]),wtd.cor(anes_combined$racial_resentment[anes_combined$Year==2020],anes_combined$morefamilyties_rescaled[anes_combined$Year==2020], weight =anes_combined$weight_variable[anes_combined$Year==2020])))

fam_ties$CI=1.96*fam_ties$std.err
fam_ties$Year=c("2004","2008","2012","2016","2020")



#Visuliations
tv_rr_cor_plot=ggplot(data =trad_val, aes(x=Year, y=correlation, group=1))+geom_errorbar(aes(ymin=correlation-CI, ymax=correlation+CI),width=.1,)+geom_point() +ylab("Correlation with Racial Resentment")+ xlab("Year")+ggtitle("Traditional Family Values")+ylim(0,.7)

ms_rr_cor_plot=ggplot(data =mod_sex, aes(x=Year, y=correlation, group=1))+geom_errorbar(aes(ymin=correlation-CI, ymax=correlation+CI),width=.1,)+geom_point() +ylab("")+ xlab("Year")+ggtitle("Modern Sexism")+ylim(0,.65)

gd_rr_cor_plot=ggplot(data =gen_dis, aes(x=Year, y=correlation, group=1))+geom_errorbar(aes(ymin=correlation-CI, ymax=correlation+CI),width=.1,)+geom_point() +ylab("")+ xlab("Year")+ggtitle("Gender Discrimination")+ylim(0,.65)

femft_rr_cor_plot=ggplot(data =ft_fem, aes(x=Year, y=correlation, group=1))+geom_errorbar(aes(ymin=correlation-CI, ymax=correlation+CI),width=.1,)+geom_point() +ylab("")+ xlab("Year")+ggtitle("Feminist FT")+ylim(0,.65)

famties_rr_cor_plot=ggplot(data =fam_ties, aes(x=Year, y=correlation, group=1))+geom_errorbar(aes(ymin=correlation-CI, ymax=correlation+CI),width=.1,)+geom_point() +ylab("")+ xlab("Year")+ggtitle("More Family Ties")+ylim(0,.65)

all_cor_plots <- ggarrange(tv_rr_cor_plot, ms_rr_cor_plot,gd_rr_cor_plot, ncol = 3, nrow = 1,font.label = list(size=12),vjust = .5)
ggexport(all_cor_plots,filename = "Tables and Figures/Correlations with Racial Resentment_RR.pdf",height =4,width = 7.5 )


all_cor_plots <- ggarrange(tv_rr_cor_plot, ms_rr_cor_plot,gd_rr_cor_plot,femft_rr_cor_plot,famties_rr_cor_plot,  ncol = 3, nrow = 2,font.label = list(size=10),vjust = .5)
ggexport(all_cor_plots,filename = "Tables and Figures/Correlations with Racial Resentment_RR appendix.pdf",height =6,width = 7.3 )
```


Subset Data to run models for each year
```{r}
anes_04=subset(anes_combined, Year==2004)
anes_08=subset(anes_combined, Year==2008)
anes_12=subset(anes_combined, Year==2012)
anes_16=subset(anes_combined, Year==2016)
anes_20=subset(anes_combined, Year==2020)
```

#Regression Results- Using Individual models for each year
```{r}
#Traditional Family Values Index
mod1=lm(traditional_values_index~ racial_resentment + woman + pid +egalitarianism+ scope_of_gov+ideology_3pt+moral_traditionalism+age+education+married+income+homemaker+biblical_literalism+church_attendance+religion + region, data = anes_20,weights = weight_variable)

mod2=lm(traditional_values_index~ racial_resentment + woman + pid +egalitarianism+ scope_of_gov+ideology_3pt+moral_traditionalism+age+education+married+income+homemaker+biblical_literalism+church_attendance+religion + region, data = anes_16,weights = weight_variable)


mod3=lm(traditional_values_index~ racial_resentment + woman + pid +egalitarianism+ scope_of_gov+ideology_3pt+moral_traditionalism+age+education+married+income+homemaker+biblical_literalism+church_attendance+religion + region, data = anes_12,weights = weight_variable)

mod4=lm(traditional_values_index~ racial_resentment + woman + pid +egalitarianism+ scope_of_gov+ideology_3pt+moral_traditionalism+age+education+married+income+homemaker+biblical_literalism+church_attendance+religion + region, data = anes_08,weights = weight_variable)


mod5=lm(traditional_values_index~ racial_resentment + woman + pid +egalitarianism+ scope_of_gov+ideology_3pt+moral_traditionalism+age+education+married+income+homemaker+biblical_literalism+church_attendance+religion + region, data = anes_04,weights = weight_variable)



library(texreg)
htmlreg(list(mod1, mod2,mod3,mod4,mod5),caption = "Determinants of Traditional Family Roles (2004-2020)", file = "Tables and Figures/Traditional_Family_Roles_RR.doc",
        stars = c(.01,.05,.1),single.row = FALSE,custom.model.names = c("Traditional Family Roles 2020","Traditional Family Roles 2016","Traditional Family Roles 2012","Traditional Family Roles 2008","Traditional Family Roles 2004" ),custom.coef.names = c("Constant","Racial Resentment","Woman","Party","Egalitarianism","Scope of Government","Ideology","Moral Traditionalism","Age","Education","Marriage","Income","Homemaker","Biblical Literalism","Service Attendance", "Evangelical","Catholic","Other Denomination/Religion","Northeast","Midwest","West"))




#Modern Sexism Index
mod1=lm(modern_sexism_index~ racial_resentment + woman + pid +egalitarianism+ scope_of_gov+ideology_3pt+moral_traditionalism+age+education+married+income+homemaker+biblical_literalism+church_attendance+religion + region, data = anes_20,weights = weight_variable)

mod2=lm(modern_sexism_index~ racial_resentment + woman + pid +egalitarianism+ scope_of_gov+ideology_3pt+moral_traditionalism+age+education+married+income+homemaker+biblical_literalism+church_attendance+religion + region, data = anes_16,weights = weight_variable)

mod3=lm(modern_sexism_index~ racial_resentment + woman + pid +egalitarianism+ scope_of_gov+ideology_3pt+moral_traditionalism+age+education+married+income+homemaker+biblical_literalism+church_attendance+religion + region, data = anes_12,weights = weight_variable)

mod4=lm(modern_sexism_index~ racial_resentment + woman + pid +egalitarianism+ scope_of_gov+ideology_3pt+moral_traditionalism+age+education+married+income+homemaker+biblical_literalism+church_attendance+religion + region, data = anes_08,weights = weight_variable)

mod5=lm(modern_sexism_index~ racial_resentment + woman + pid +egalitarianism+ scope_of_gov+ideology_3pt+moral_traditionalism+age+education+married+income+homemaker+biblical_literalism+church_attendance+religion + region, data = anes_04,weights = weight_variable)

library(texreg)
htmlreg(list(mod1, mod2,mod3,mod4,mod5),caption = "Determinants of Modern Sexism (2004-2020)", file = "Tables and Figures/Modern Sexism_RR.doc",
        stars = c(.01,.05,.1),single.row = FALSE,custom.model.names = c("Modern Sexism 2020","Modern Sexism 2016","Modern Sexism 2012","Modern Sexism 2008","Modern Sexism 2004"),custom.coef.names = c("Constant","Racial Resentment","Woman","Party","Egalitarianism","Scope of Government","Ideology","Moral Traditionalism","Age","Education","Marriage","Income","Homemaker","Biblical Literalism","Service Attendance", "Evangelical","Catholic","Other Denomination/Religion","Northeast","Midwest","West"))


#Perceived Gender Discrimination-OLS
mod1=lm(percieved_gender_discrimination_rescaled~ racial_resentment + woman + pid +egalitarianism+ scope_of_gov+ideology_3pt+moral_traditionalism+age+education+married+income+homemaker+biblical_literalism+church_attendance+religion + region, data = anes_20,weights = weight_variable)

mod2=lm(percieved_gender_discrimination_rescaled~ racial_resentment + woman + pid +egalitarianism+ scope_of_gov+ideology_3pt+moral_traditionalism+age+education+married+income+homemaker+biblical_literalism+church_attendance+religion + region, data = anes_16,weights = weight_variable)

mod3=lm(percieved_gender_discrimination_rescaled~ racial_resentment + woman + pid +egalitarianism+ scope_of_gov+ideology_3pt+moral_traditionalism+age+education+married+income+homemaker+biblical_literalism+church_attendance+religion + region, data = anes_12,weights = weight_variable)

mod4=lm(percieved_gender_discrimination_rescaled~ racial_resentment + woman + pid +egalitarianism+ scope_of_gov+ideology_3pt+moral_traditionalism+age+education+married+income+homemaker+biblical_literalism+church_attendance+religion + region, data = anes_08,weights = weight_variable)
summary(mod4)

mod5=lm(percieved_gender_discrimination_rescaled~ racial_resentment + woman + pid +egalitarianism+ scope_of_gov+ideology_3pt+moral_traditionalism+age+education+married+income+homemaker+biblical_literalism+church_attendance+religion + region, data = anes_04,weights = weight_variable)


library(texreg)
htmlreg(list(mod1, mod2,mod3,mod4,mod5),caption = "Determinants of Percieved Gender Discrimination (2004-2020)_OLS", file = "Tables and Figures/Gender Discrimination_RR_OLS.doc",
        stars = c(.01,.05,.1),single.row = FALSE,custom.model.names = c("Gender Discrimination 2020","Gender Discrimination 2016","Gender Discrimination 2012","Gender Discrimination 2008","Gender Discrimination 2004"),custom.coef.names = c("Constant","Racial Resentment","Woman","Party","Egalitarianism","Scope of Government","Ideology","Moral Traditionalism","Age","Education","Marriage","Income","Homemaker","Biblical Literalism","Service Attendance", "Evangelical","Catholic","Other Denomination/Religion","Northeast","Midwest","West"))


#Perceived Gender Discrimination-Ordinal
library(MASS)

mod1=polr(as.factor(percieved_gender_discrimination)~ racial_resentment + woman + pid +egalitarianism+ scope_of_gov+ideology_3pt+moral_traditionalism+age+education+married+income+homemaker+biblical_literalism+church_attendance+religion + region, data = anes_20,weights = weight_variable, Hess = T, method = "probit")

mod2=polr(as.factor(percieved_gender_discrimination)~ racial_resentment + woman + pid +egalitarianism+ scope_of_gov+ideology_3pt+moral_traditionalism+age+education+married+income+homemaker+biblical_literalism+church_attendance+religion + region, data = anes_16,weights = weight_variable, Hess = T, method = "probit")

mod3=polr(as.factor(percieved_gender_discrimination)~ racial_resentment + woman + pid +egalitarianism+ scope_of_gov+ideology_3pt+moral_traditionalism+age+education+married+income+homemaker+biblical_literalism+church_attendance+religion + region, data = anes_12,weights = weight_variable, Hess = T, method = "probit")

mod4=polr(as.factor(percieved_gender_discrimination)~ racial_resentment + woman + pid +egalitarianism+ scope_of_gov+ideology_3pt+moral_traditionalism+age+education+married+income+homemaker+biblical_literalism+church_attendance+religion + region, data = anes_08,weights = weight_variable, Hess = T, method = "probit")

mod5=polr(as.factor(percieved_gender_discrimination)~ racial_resentment + woman + pid +egalitarianism+ scope_of_gov+ideology_3pt+moral_traditionalism+age+education+married+income+homemaker+biblical_literalism+church_attendance+religion + region, data = anes_04,weights = weight_variable, Hess = T, method = "probit")

summary(mod5)
library(texreg)

htmlreg(list(mod1, mod2,mod3,mod4,mod5),caption = "Determinants of Percieved Gender Discrimination (2004-2020)", file = "Tables and Figures/Gender Discrimination_RR_Ordinal.doc",
        stars = c(.01,.05,.1),single.row = FALSE,custom.model.names = c("Gender Discrimination 2020","Gender Discrimination 2016","Gender Discrimination 2012","Gender Discrimination 2008","Gender Discrimination 2004"),custom.coef.names = c("Racial Resentment","Woman","Party","Egalitarianism","Scope of Government","Ideology","Moral Traditionalism","Age","Education","Marriage","Income","Homemaker","Biblical Literalism","Service Attendance", "Evangelical","Catholic","Other Denomination/Religion","Northeast","Midwest","West","Cut-point 1", "Cut-point 2","Cut-point 3","Cut-point 4"))



#Feminist Feeling Thermometer
mod1=lm(ft_feminists~ racial_resentment + woman + pid +egalitarianism+ scope_of_gov+ideology_3pt+moral_traditionalism+age+education+married+income+homemaker+biblical_literalism+church_attendance+religion + region, data = anes_20,weights = weight_variable)

mod2=lm(ft_feminists~ racial_resentment + woman + pid +egalitarianism+ scope_of_gov+ideology_3pt+moral_traditionalism+age+education+married+income+homemaker+biblical_literalism+church_attendance+religion + region, data = anes_16,weights = weight_variable)

mod3=lm(ft_feminists~ racial_resentment + woman + pid +egalitarianism+ scope_of_gov+ideology_3pt+moral_traditionalism+age+education+married+income+homemaker+biblical_literalism+church_attendance+religion + region, data = anes_12,weights = weight_variable)

mod4=lm(ft_feminists~ racial_resentment + woman + pid +egalitarianism+ scope_of_gov+ideology_3pt+moral_traditionalism+age+education+married+income+homemaker+biblical_literalism+church_attendance+religion + region, data = anes_08,weights = weight_variable)

mod5=lm(ft_feminists~ racial_resentment + woman + pid +egalitarianism+ scope_of_gov+ideology_3pt+moral_traditionalism+age+education+married+income+homemaker+biblical_literalism+church_attendance+religion + region, data = anes_04,weights = weight_variable)

library(texreg)
htmlreg(list(mod1, mod2,mod3,mod4,mod5),caption = "Determinants of Feminist Feeling Thermometer  Rating (2004-2020)", file = "Tables and Figures/Feminist FT_RR.doc",
        stars = c(.01,.05,.1),single.row = FALSE,custom.model.names = c("Feminist FT 2020","Feminist FT 2016","Feminist FT 2012","Feminist FT 2008","Feminist FT 2004"),custom.coef.names = c("Constant","Racial Resentment","Woman","Party","Egalitarianism","Scope of Government","Ideology","Moral Traditionalism","Age","Education","Marriage","Income","Homemaker","Biblical Literalism","Service Attendance", "Evangelical","Catholic","Other Denomination/Religion","Northeast", "Midwest","West"))


#More family ties
mod1=lm(morefamilyties_rescaled~ racial_resentment + woman + pid +egalitarianism+ scope_of_gov+ideology_3pt+moral_traditionalism+age+education+married+income+homemaker+biblical_literalism+church_attendance+religion + region, data = anes_20,weights = weight_variable)

mod2=lm(morefamilyties_rescaled~ racial_resentment + woman + pid +egalitarianism+ scope_of_gov+ideology_3pt+moral_traditionalism+age+education+married+income+homemaker+biblical_literalism+church_attendance+religion + region, data = anes_16,weights = weight_variable)

mod3=lm(morefamilyties_rescaled~ racial_resentment + woman + pid +egalitarianism+ scope_of_gov+ideology_3pt+moral_traditionalism+age+education+married+income+homemaker+biblical_literalism+church_attendance+religion + region, data = anes_12,weights = weight_variable)

mod4=lm(morefamilyties_rescaled~ racial_resentment + woman + pid +egalitarianism+ scope_of_gov+ideology_3pt+moral_traditionalism+age+education+married+income+homemaker+biblical_literalism+church_attendance+religion + region, data = anes_08,weights = weight_variable)

mod5=lm(morefamilyties_rescaled~ racial_resentment + woman + pid +egalitarianism+ scope_of_gov+ideology_3pt+moral_traditionalism+age+education+married+income+homemaker+biblical_literalism+church_attendance+religion + region, data = anes_04,weights = weight_variable)

library(texreg)
htmlreg(list(mod1, mod2,mod3,mod4,mod5),caption = "Determinants of Attitudes Towards the Importance of Family Ties (2004-2020)", file = "Tables and Figures/Family Ties_RR.doc",
        stars = c(.01,.05,.1),single.row = FALSE,custom.model.names = c("Family Ties 2020","Family Ties 2016","Family Ties 2012","Family Ties 2008","Family Ties 2004"),custom.coef.names = c("Constant","Racial Resentment","Woman","Party","Egalitarianism","Scope of Government","Ideology","Moral Traditionalism","Age","Education","Marriage","Income","Homemaker","Biblical Literalism","Service Attendance", "Evangelical","Catholic","Other Denomination/Religion","Northeast", "Midwest","West"))


#Hostile Sexism Feeling Thermometer
mod1=lm(hostile_sexism_index~ racial_resentment + woman + pid +egalitarianism+ scope_of_gov+ideology_3pt+moral_traditionalism+age+education+married+income+homemaker+biblical_literalism+church_attendance+religion + region, data = anes_20,weights = weight_variable)

mod2=lm(hostile_sexism_index~ racial_resentment + woman + pid +egalitarianism+ scope_of_gov+ideology_3pt+moral_traditionalism+age+education+married+income+homemaker+biblical_literalism+church_attendance+religion + region, data = anes_16,weights = weight_variable)

library(texreg)
htmlreg(list(mod1, mod2),caption = "Determinants of Hostile Sexism (2016-2020)", file = "Tables and Figures/Hostile Sexism_RR.doc",
        stars = c(.01,.05,.1),single.row = FALSE,custom.model.names = c("Hostile Sexism 2020","Hostile Sexism 2016"),custom.coef.names = c("Constant","Racial Resentment","Woman","Party","Egalitarianism","Scope of Government","Ideology","Moral Traditionalism","Age","Education","Marriage","Income","Homemaker","Biblical Literalism","Service Attendance", "Evangelical","Catholic","Other Denomination/Religion","Northeast", "Midwest","West"))


summary(anes_20$innocentremarks_as_sexist)
```


#Regression Results-Pooled Analysis with fixed effects for each year (additive)
```{r}
class(anes_combined$Year)
anes_combined$Year=as.factor(anes_combined$Year)
class(anes_combined$Year)

mod1=lm(traditional_values_index~ racial_resentment + woman + pid +egalitarianism+ scope_of_gov+ideology_3pt+moral_traditionalism+age+education+married+income+homemaker+biblical_literalism+church_attendance+religion + region+Year, data = anes_combined,weights = weight_variable)


mod2=lm(modern_sexism_index~ racial_resentment + woman + pid +egalitarianism+ scope_of_gov+ideology_3pt+moral_traditionalism+age+education+married+income+homemaker+biblical_literalism+church_attendance+religion + region+Year, data = anes_combined,weights = weight_variable)

mod3=lm(percieved_gender_discrimination~ racial_resentment + woman + pid +egalitarianism+ scope_of_gov+ideology_3pt+moral_traditionalism+age+education+married+income+homemaker+biblical_literalism+church_attendance+religion + region+Year, data = anes_combined,weights = weight_variable)

mod4=lm(ft_feminists~ racial_resentment + woman + pid +egalitarianism+ scope_of_gov+ideology_3pt+moral_traditionalism+age+education+married+income+homemaker+biblical_literalism+church_attendance+religion + region+Year, data = anes_combined,weights = weight_variable)

mod5=lm(morefamilyties_rescaled~ racial_resentment + woman + pid +egalitarianism+ scope_of_gov+ideology_3pt+moral_traditionalism+age+education+married+income+homemaker+biblical_literalism+church_attendance+religion + region+Year, data = anes_combined,weights = weight_variable)

library(texreg)
htmlreg(list(mod1, mod2,mod3,mod4,mod5),caption = "Determinants of Gender Attitudes(2004-2020)", file = "Tables and Figures/Additive Pooled Models_RR.doc",
        stars = c(.01,.05,.1),single.row = FALSE,custom.model.names = c("TraditionalFamily Values","Modern Sexism","Gender Discrimination", "Feminist Feeling Thermometer","Strong Family Ties"),custom.coef.names = c("Constant","Racial Resentment","Woman","Party","Egalitarianism","Scope of Government","Ideology","Moral Traditionalism","Age","Education","Marriage","Income","Homemaker","Biblical Literalism","Service Attendance","Evangelical","Catholic","Other Denomination/Religion","Northeast", "Midwest","West","2008","2012","2016","2020"))




```

#Regression Results-Pooled Analysis with interaction term for time effects for each year (interactive)
```{r}
class(anes_combined$Year)
anes_combined$Year=as.factor(anes_combined$Year)
class(anes_combined$Year)
table(anes_combined$Year)
anes_combined$time=ifelse(anes_combined$Year=="2004",0,
                          ifelse(anes_combined$Year=="2008",1,
                                 ifelse(anes_combined$Year=="2012",2,
                                        ifelse(anes_combined$Year=="2016",3,4))))
table(anes_combined$Year)
table(anes_combined$time)
anes_combined$time_rescaled=rescale(anes_combined$time)
table(anes_combined$time_rescaled)



mod1=lm(traditional_values_index~ racial_resentment + racial_resentment*time_rescaled+woman + pid +egalitarianism+ scope_of_gov+ideology_3pt+moral_traditionalism+age+education+married+income+homemaker+biblical_literalism+church_attendance+religion + region, data = anes_combined,weights = weight_variable)


mod2=lm(modern_sexism_index~ racial_resentment + racial_resentment*time_rescaled+ woman + pid +egalitarianism+ scope_of_gov+ideology_3pt+moral_traditionalism+age+education+married+income+homemaker+biblical_literalism+church_attendance+religion + region, data = anes_combined,weights = weight_variable)

mod3=lm(percieved_gender_discrimination~ racial_resentment+ racial_resentment*time_rescaled + woman + pid +egalitarianism+ scope_of_gov+ideology_3pt+moral_traditionalism+age+education+married+income+homemaker+biblical_literalism+church_attendance+religion + region, data = anes_combined,weights = weight_variable)

mod4=lm(ft_feminists~ racial_resentment + racial_resentment*time_rescaled+ woman + pid +egalitarianism+ scope_of_gov+ideology_3pt+moral_traditionalism+age+education+married+income+homemaker+biblical_literalism+church_attendance+religion + region, data = anes_combined,weights = weight_variable)

mod5=lm(hostile_sexism_index~ racial_resentment+ racial_resentment*time_rescaled + woman + pid +egalitarianism+ scope_of_gov+ideology_3pt+moral_traditionalism+age+education+married+income+homemaker+biblical_literalism+church_attendance+religion + region, data = anes_combined,weights = weight_variable)

mod6=lm(morefamilyties_rescaled~ racial_resentment+ racial_resentment*time_rescaled + woman + pid +egalitarianism+ scope_of_gov+ideology_3pt+moral_traditionalism+age+education+married+income+homemaker+biblical_literalism+church_attendance+religion + region, data = anes_combined,weights = weight_variable)



library(texreg)
htmlreg(list(mod1, mod2,mod3),caption = "Determinants of Gender Attitudes(2004-2020)", file = "Tables and Figures/Interactive Pooled Models_RR.doc",
        stars = c(.01,.05,.1),single.row = FALSE,custom.model.names = c("TraditionalFamily Values","Modern Sexism","Gender Discrimination"),custom.coef.names = c("Constant","Racial Resentment","Time","Woman","Party","Egalitarianism","Scope of Government","Ideology","Moral Traditionalism","Age","Education","Marriage","Income","Homemaker","Biblical Literalism","Service Attendance","Evangelical","Catholic","Other Denomination/Religion","Northeast", "Midwest","West","Racial Resentment X Time"))

library(texreg)
htmlreg(list(mod4,mod5,mod6),caption = "Determinants of Gender Attitudes(2004-2020)", file = "Tables and Figures/Interactive Pooled Models_RR_Apenndix.doc",
        stars = c(.01,.05,.1),single.row = FALSE,custom.model.names = c("Feminist FT","Hostile Sexism","Traditional Family Ties"),custom.coef.names = c("Constant","Racial Resentment","Time","Woman","Party","Egalitarianism","Scope of Government","Ideology","Moral Traditionalism","Age","Education","Marriage","Income","Homemaker","Biblical Literalism","Service Attendance","Evangelical","Catholic","Other Denomination/Religion","Northeast", "Midwest","West","Racial Resentment X Time"))


#Calculate Marginal Effects of Racial Resentment over DVs over time
library(margins)
trad_val_ame =summary(margins(mod1,at=list(time_rescaled=c(0,.25,.5,.75,1)), variables = "racial_resentment",  change=c(0,1), vce = "bootstrap",type="response"))
mod_sex_ame =summary(margins(mod2,at=list(time_rescaled=c(0,.25,.5,.75,1)), variables = "racial_resentment",  change=c(0,1), vce = "bootstrap",type="response"))
gen_dis_ame =summary(margins(mod3,at=list(time_rescaled=c(0,.25,.5,.75,1)), variables = "racial_resentment",  change=c(0,1), vce = "bootstrap",type="response"))
fem_ft_ame =summary(margins(mod4,at=list(time_rescaled=c(0,.25,.5,.75,1)), variables = "racial_resentment",  change=c(0,1), vce = "bootstrap",type="response"))
hos_sex_ame =summary(margins(mod5,at=list(time_rescaled=c(.75,1)), variables = "racial_resentment",  change=c(0,1), vce = "bootstrap",type="response"))
fam_ties_ame =summary(margins(mod6,at=list(time_rescaled=c(0,.25,.5,.75,1)), variables = "racial_resentment",  change=c(0,1), vce = "bootstrap",type="response"))


trad_val_ame$Year= c("2004","2008","2012","2016","2020")
mod_sex_ame$Year= c("2004","2008","2012","2016","2020")
gen_dis_ame$Year= c("2004","2008","2012","2016","2020")
fem_ft_ame$Year= c("2004","2008","2012","2016","2020")
hos_sex_ame$Year= c("2016","2020")
fam_ties_ame$Year= c("2004","2008","2012","2016","2020")


#Create Plots
me_tradvalues=ggplot(data =trad_val_ame, aes(x=Year, y=AME, group=1))+geom_errorbar(aes(ymin=lower, ymax=upper),width=.1,)+geom_point() +ylab("Marginal Effect of Racial Resentment")+ xlab("Year")+ggtitle("Traditional Family Values")+ylim(0,.5)+
    geom_hline(yintercept=0, alpha=.6)

me_modsex=ggplot(data =mod_sex_ame, aes(x=Year, y=AME, group=1))+geom_errorbar(aes(ymin=lower, ymax=upper),width=.1,)+geom_point() +ylab("Marginal Effect of Racial Resentment")+ xlab("Year")+ggtitle("Modern Sexism")+ylim(0,.5)+
    geom_hline(yintercept=0, alpha=.6)

me_gendiscrim=ggplot(data =gen_dis_ame, aes(x=Year, y=AME, group=1))+geom_errorbar(aes(ymin=lower, ymax=upper),width=.1,)+geom_point() +ylab("Marginal Effect of Racial Resentment")+ xlab("Year")+ggtitle("Gender Discrimination")+ylim(0,1.15)+
    geom_hline(yintercept=0, alpha=.6)

me_femFT=ggplot(data =fem_ft_ame, aes(x=Year, y=AME, group=1))+geom_errorbar(aes(ymin=lower, ymax=upper),width=.1,)+geom_point() +ylab("Marginal Effect of Racial Resentment")+ xlab("Year")+ggtitle("Feminist FT")+ylim(0,.5)+
    geom_hline(yintercept=0, alpha=.6)

me_hossex=ggplot(data =hos_sex_ame, aes(x=Year, y=AME, group=1))+geom_errorbar(aes(ymin=lower, ymax=upper),width=.1,)+geom_point() +ylab("Marginal Effect of Racial Resentment")+ xlab("Year")+ggtitle("Hostile Sexism")+ylim(0,.5)+
    geom_hline(yintercept=0, alpha=.6)

me_famties=ggplot(data =fam_ties_ame, aes(x=Year, y=AME, group=1))+geom_errorbar(aes(ymin=lower, ymax=upper),width=.1,)+geom_point() +ylab("Marginal Effect of Racial Resentment")+ xlab("Year")+ggtitle("Traditional Family Ties")+ylim(0,.5)+
    geom_hline(yintercept=0, alpha=.6)

ame_plots <- ggarrange(me_tradvalues,me_modsex ,me_gendiscrim, ncol = 3, nrow = 1,font.label = list(size=12),vjust = .5)
ggexport(ame_plots,filename = "Tables and Figures/Marginal Effect Racial Resentment_Main Text.pdf",height =4,width = 7.5 )


ame_plots <- ggarrange(me_femFT,me_hossex, ncol = 2, nrow = 1,font.label = list(size=12),vjust = .5)
ggexport(ame_plots,filename = "Tables and Figures/Marginal Effect Racial Resentment_Appendix.pdf",height =4,width = 7.5 )


```


#Reverse Regression Results- Using Individual models for each year to predict Racial Resetnment
```{r}
#Traditional Family Values Index
summary(anes_combined$racial_resentment)
mod1=lm( racial_resentment ~ traditional_values_index+ woman + pid +egalitarianism+ scope_of_gov+ideology_3pt+moral_traditionalism+age+education+married+income+homemaker+biblical_literalism+church_attendance+religion + region, data = anes_20,weights = weight_variable)

mod2=lm( racial_resentment ~ traditional_values_index+ woman + pid +egalitarianism+ scope_of_gov+ideology_3pt+moral_traditionalism+age+education+married+income+homemaker+biblical_literalism+church_attendance+religion + region, data = anes_16,weights = weight_variable)

mod3=lm( racial_resentment ~ traditional_values_index+ woman + pid +egalitarianism+ scope_of_gov+ideology_3pt+moral_traditionalism+age+education+married+income+homemaker+biblical_literalism+church_attendance+religion + region, data = anes_12,weights = weight_variable)

mod4=lm( racial_resentment ~ traditional_values_index+ woman + pid +egalitarianism+ scope_of_gov+ideology_3pt+moral_traditionalism+age+education+married+income+homemaker+biblical_literalism+church_attendance+religion + region, data = anes_08,weights = weight_variable)


mod5=lm( racial_resentment ~ traditional_values_index+ woman + pid +egalitarianism+ scope_of_gov+ideology_3pt+moral_traditionalism+age+education+married+income+homemaker+biblical_literalism+church_attendance+religion + region, data = anes_04,weights = weight_variable)




library(texreg)
htmlreg(list(mod1, mod2,mod3,mod4,mod5),caption = "Predicting Racial Resentment With Traditional Family Roles (2004-2020)", file = "Tables and Figures/Traditional_Family_Roles_RR_reversed.doc",
        stars = c(.01,.05,.1),single.row = FALSE,custom.model.names = c("Racial Resentment 2020","Racial Resentment 2016","Racial Resentment 2012","Racial Resentment 2008","Racial Resentment 2004" ),custom.coef.names = c("Constant","Traditional Family Roles","Woman","Party","Egalitarianism","Scope of Government","Ideology","Moral Traditionalism","Age","Education","Marriage","Income","Homemaker","Biblical Literalism","Service Attendance", "Evangelical","Catholic","Other Denomination/Religion","Northeast","Midwest","West"))




#Modern Sexism Index
mod1=lm( racial_resentment ~ modern_sexism_index + woman + pid +egalitarianism+ scope_of_gov+ideology_3pt+moral_traditionalism+age+education+married+income+homemaker+biblical_literalism+church_attendance+religion + region, data = anes_20,weights = weight_variable)

mod2=lm( racial_resentment ~ modern_sexism_index + woman + pid +egalitarianism+ scope_of_gov+ideology_3pt+moral_traditionalism+age+education+married+income+homemaker+biblical_literalism+church_attendance+religion + region, data = anes_16,weights = weight_variable)

mod3=lm( racial_resentment ~ modern_sexism_index + woman + pid +egalitarianism+ scope_of_gov+ideology_3pt+moral_traditionalism+age+education+married+income+homemaker+biblical_literalism+church_attendance+religion + region, data = anes_12,weights = weight_variable)

mod4=lm( racial_resentment ~ modern_sexism_index + woman + pid +egalitarianism+ scope_of_gov+ideology_3pt+moral_traditionalism+age+education+married+income+homemaker+biblical_literalism+church_attendance+religion + region, data = anes_08,weights = weight_variable)

mod5=lm( racial_resentment ~ modern_sexism_index + woman + pid +egalitarianism+ scope_of_gov+ideology_3pt+moral_traditionalism+age+education+married+income+homemaker+biblical_literalism+church_attendance+religion + region, data = anes_04,weights = weight_variable)

library(texreg)
htmlreg(list(mod1, mod2,mod3,mod4,mod5),caption = "Predicting Racial Resentment With Modern Sexism (2004-2020)", file = "Tables and Figures/Modern Sexism_RR_reversed.doc",
        stars = c(.01,.05,.1),single.row = FALSE,custom.model.names = c("Racial Resentment 2020","Racial Resentment 2016","Racial Resentment 2012","Racial Resentment 2008","Racial Resentment 2004"),custom.coef.names = c("Constant","Modern Sexism","Woman","Party","Egalitarianism","Scope of Government","Ideology","Moral Traditionalism","Age","Education","Marriage","Income","Homemaker","Biblical Literalism","Service Attendance", "Evangelical","Catholic","Other Denomination/Religion","Northeast","Midwest","West"))


#Perceived Gender Discrimination
mod1=lm( racial_resentment ~ percieved_gender_discrimination + woman + pid +egalitarianism+ scope_of_gov+ideology_3pt+moral_traditionalism+age+education+married+income+homemaker+biblical_literalism+church_attendance+religion + region, data = anes_20,weights = weight_variable)

mod2=lm( racial_resentment ~ percieved_gender_discrimination + woman + pid +egalitarianism+ scope_of_gov+ideology_3pt+moral_traditionalism+age+education+married+income+homemaker+biblical_literalism+church_attendance+religion + region, data = anes_16,weights = weight_variable)

mod3=lm( racial_resentment ~ percieved_gender_discrimination + woman + pid +egalitarianism+ scope_of_gov+ideology_3pt+moral_traditionalism+age+education+married+income+homemaker+biblical_literalism+church_attendance+religion + region, data = anes_12,weights = weight_variable)

mod4=lm( racial_resentment ~ percieved_gender_discrimination + woman + pid +egalitarianism+ scope_of_gov+ideology_3pt+moral_traditionalism+age+education+married+income+homemaker+biblical_literalism+church_attendance+religion + region, data = anes_08,weights = weight_variable)

mod5=lm( racial_resentment ~ percieved_gender_discrimination + woman + pid +egalitarianism+ scope_of_gov+ideology_3pt+moral_traditionalism+age+education+married+income+homemaker+biblical_literalism+church_attendance+religion + region, data = anes_04,weights = weight_variable)

library(texreg)
htmlreg(list(mod1, mod2,mod3,mod4,mod5),caption = "Predicting Racial Resentment With Percieved Gender Discrimination (2004-2020)", file = "Tables and Figures/Gender Discrimination_RR_reversed.doc",
        stars = c(.01,.05,.1),single.row = FALSE,custom.model.names = c("Racial Resentment 2020","Racial Resentment 2016","Racial Resentment 2012","Racial Resentment 2008","Racial Resentment 2004"),custom.coef.names = c("Constant","Gender Discrimination","Woman","Party","Egalitarianism","Scope of Government","Ideology","Moral Traditionalism","Age","Education","Marriage","Income","Homemaker","Biblical Literalism","Service Attendance", "Evangelical","Catholic","Other Denomination/Religion","Northeast","Midwest","West"))



#Feminist Feeling Thermometer
mod1=lm( racial_resentment ~ ft_feminists + woman + pid +egalitarianism+ scope_of_gov+ideology_3pt+moral_traditionalism+age+education+married+income+homemaker+biblical_literalism+church_attendance+religion + region, data = anes_20,weights = weight_variable)

mod2=lm( racial_resentment ~ ft_feminists + woman + pid +egalitarianism+ scope_of_gov+ideology_3pt+moral_traditionalism+age+education+married+income+homemaker+biblical_literalism+church_attendance+religion + region, data = anes_16,weights = weight_variable)

mod3=lm( racial_resentment ~ ft_feminists + woman + pid +egalitarianism+ scope_of_gov+ideology_3pt+moral_traditionalism+age+education+married+income+homemaker+biblical_literalism+church_attendance+religion + region, data = anes_12,weights = weight_variable)

mod4=lm( racial_resentment ~ ft_feminists + woman + pid +egalitarianism+ scope_of_gov+ideology_3pt+moral_traditionalism+age+education+married+income+homemaker+biblical_literalism+church_attendance+religion + region, data = anes_08,weights = weight_variable)

mod5=lm( racial_resentment ~ ft_feminists + woman + pid +egalitarianism+ scope_of_gov+ideology_3pt+moral_traditionalism+age+education+married+income+homemaker+biblical_literalism+church_attendance+religion + region, data = anes_04,weights = weight_variable)

library(texreg)
htmlreg(list(mod1, mod2,mod3,mod4,mod5),caption = "Predicting Racial Resentment With Feminist Feeling Thermometer  Rating (2004-2020)", file = "Tables and Figures/Feminist FT_RR_reversed.doc",
        stars = c(.01,.05,.1),single.row = FALSE,custom.model.names = c("Racial Resentment 2020","Racial Resentment 2016","Racial Resentment 2012","Racial Resentment 2008","Racial Resentment 2004"),custom.coef.names = c("Constant","Feminist FT","Woman","Party","Egalitarianism","Scope of Government","Ideology","Moral Traditionalism","Age","Education","Marriage","Income","Homemaker","Biblical Literalism","Service Attendance", "Evangelical","Catholic","Other Denomination/Religion","Northeast", "Midwest","West"))


```


#Reverse Regression Results-Pooled Analysis with fixed effects for each year (additive)

```{r}
class(anes_combined$Year)
anes_combined$Year=as.factor(anes_combined$Year)
class(anes_combined$Year)

mod1=lm( racial_resentment ~ traditional_values_index+ woman + pid +egalitarianism+ scope_of_gov+ideology_3pt+moral_traditionalism+age+education+married+income+homemaker+biblical_literalism+church_attendance+religion + region+Year, data = anes_combined,weights = weight_variable)

mod2=lm( racial_resentment ~ modern_sexism_index + woman + pid +egalitarianism+ scope_of_gov+ideology_3pt+moral_traditionalism+age+education+married+income+homemaker+biblical_literalism+church_attendance+religion + region+Year, data = anes_combined,weights = weight_variable)

mod3=lm( racial_resentment ~ percieved_gender_discrimination + woman + pid +egalitarianism+ scope_of_gov+ideology_3pt+moral_traditionalism+age+education+married+income+homemaker+biblical_literalism+church_attendance+religion + region+Year, data = anes_combined,weights = weight_variable)

mod4=lm( racial_resentment ~ ft_feminists + woman + pid +egalitarianism+ scope_of_gov+ideology_3pt+moral_traditionalism+age+education+married+income+homemaker+biblical_literalism+church_attendance+religion + region+Year, data = anes_combined,weights = weight_variable)

mod5=lm( racial_resentment ~ morefamilyties + woman + pid +egalitarianism+ scope_of_gov+ideology_3pt+moral_traditionalism+age+education+married+income+homemaker+biblical_literalism+church_attendance+religion + region+Year, data = anes_combined,weights = weight_variable)

library(texreg)
htmlreg(list(mod1, mod2,mod3,mod4,mod5),caption = "Predicting RR Using Gender Attitudes(2004-2020)", file = "Tables and Figures/Additive Pooled Models_RR_reversed.doc",
        stars = c(.01,.05,.1),single.row = FALSE,custom.model.names = c("Racial Resentment","Racial Resentment","Racial Resentment","Racial Resentment","Racial Resentment"),custom.coef.names = c("Constant","TraditionalFamily Values","Modern Sexism","Gender Discrimination", "Feminist Feeling Thermometer","Strong Family Ties","Woman","Party","Egalitarianism","Scope of Government","Ideology","Moral Traditionalism","Age","Education","Marriage","Income","Homemaker","Biblical Literalism","Service Attendance","Catholic","Other Denomination/Religion","Evangelical","Northeast", "Midwest","West","2008","2012","2016","2020"))
```


#Reverse Regression Results-Pooled Analysis with interaction term for time effects for each year (interactive)
```{r}
class(anes_combined$Year)
anes_combined$Year=as.factor(anes_combined$Year)
class(anes_combined$Year)
table(anes_combined$Year)
anes_combined$time=ifelse(anes_combined$Year=="2004",0,
                          ifelse(anes_combined$Year=="2008",1,
                                 ifelse(anes_combined$Year=="2012",2,
                                        ifelse(anes_combined$Year=="2016",3,4))))
table(anes_combined$Year)
table(anes_combined$time)
anes_combined$time_rescaled=rescale(anes_combined$time)



mod1=lm( racial_resentment ~ traditional_values_index+ racial_resentment*time_rescaled+woman + pid +egalitarianism+ scope_of_gov+ideology_3pt+moral_traditionalism+age+education+married+income+homemaker+biblical_literalism+church_attendance+religion + region, data = anes_combined,weights = weight_variable)


mod2=lm( racial_resentment ~ modern_sexism_index + racial_resentment*time_rescaled+ woman + pid +egalitarianism+ scope_of_gov+ideology_3pt+moral_traditionalism+age+education+married+income+homemaker+biblical_literalism+church_attendance+religion + region, data = anes_combined,weights = weight_variable)

mod3=lm( racial_resentment ~ percieved_gender_discrimination+ racial_resentment*time_rescaled + woman + pid +egalitarianism+ scope_of_gov+ideology_3pt+moral_traditionalism+age+education+married+income+homemaker+biblical_literalism+church_attendance+religion + region, data = anes_combined,weights = weight_variable)

mod4=lm( racial_resentment ~ ft_feminists + racial_resentment*time_rescaled+ woman + pid +egalitarianism+ scope_of_gov+ideology_3pt+moral_traditionalism+age+education+married+income+homemaker+biblical_literalism+church_attendance+religion + region, data = anes_combined,weights = weight_variable)

mod5=lm(morefamilyties_rescaled~ racial_resentment+ racial_resentment*time_rescaled + woman + pid +egalitarianism+ scope_of_gov+ideology_3pt+moral_traditionalism+age+education+married+income+homemaker+biblical_literalism+church_attendance+religion + region, data = anes_combined,weights = weight_variable)

library(texreg)
htmlreg(list(mod1, mod2,mod3,mod4,mod5),caption = "Predicting RR Using Gender Attitudes (2004-2020)", file = "Tables and Figures/Interactive Pooled Models_RR_reversed.doc",
        stars = c(.01,.05,.1),single.row = FALSE,custom.model.names = c("Racial Resentment","Racial Resentment","Racial Resentment","Racial Resentment","Racial Resentment"),custom.coef.names = c("Constant","TraditionalFamily Values","Modern Sexism","Gender Discrimination", "Feminist Feeling Thermometer","Strong Family Ties","Time","Woman","Party","Egalitarianism","Scope of Government","Ideology","Moral Traditionalism","Age","Education","Marriage","Income","Homemaker","Biblical Literalism","Service Attendance","Catholic","Other Denomination/Religion","Evangelical","Northeast", "Midwest","West","Racial Resentment X Time"))
```
